package com.ocom.srvpaccess.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;;
import com.ocom.common.entity.access.EntityMjGroupPer;
import com.ocom.common.enums.DataSourceEnum;
import com.ocom.common.enums.MasterSlaveEnum;
import com.ocom.mysql.aspect.DataSourceAspect;
import com.ocom.srvpaccess.dao.IDaoGroupPer;
import com.ocom.srvpaccess.service.GroupPerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.*;


@Service
public class GroupPerServiceImpl extends ServiceImpl<IDaoGroupPer, EntityMjGroupPer> implements GroupPerService {

    @Autowired
    private IDaoGroupPer daoGroupPer;

    @DataSourceAspect(type= DataSourceEnum.PART_DB,isMaster = MasterSlaveEnum.SLAVE)
    @Override
    public List<EntityMjGroupPer> selectGroupPer(Long companyId, List<Long> pIds, Long areaId) {
        QueryWrapper<EntityMjGroupPer> groupPerQueryWrapper=Wrappers.query();
        groupPerQueryWrapper.eq("com_id",companyId);
        groupPerQueryWrapper.in("p_id",pIds);
        groupPerQueryWrapper.eq("area_id",areaId);
        return daoGroupPer.selectList(groupPerQueryWrapper);
    }

    @DataSourceAspect(type= DataSourceEnum.PART_DB,isMaster = MasterSlaveEnum.SLAVE)
    @Override
    public EntityMjGroupPer selectGroupPer(Long companyId,Long pId, Long areaId) {
        QueryWrapper<EntityMjGroupPer> groupPerQueryWrapper=Wrappers.query();
        groupPerQueryWrapper.eq("com_id",companyId);
        groupPerQueryWrapper.eq("p_id",pId);
        groupPerQueryWrapper.eq("area_id",areaId);
        groupPerQueryWrapper.last("limit 1");
        return daoGroupPer.selectOne(groupPerQueryWrapper);
    }
}
